import { MongoClient } from 'mongodb'
import Element from './element'
import Ajax from './ajax'
import Mock from './mock'
import Suite from './suite'
import SuiteDetail from './suiteDetail'
import Config from './config'
import Log from './log'
import Screenshot from './screenshot'
import Plan from './plan'
import BaseEnvLog from './baseEnvLog'
import StepCollection from './stepCollection'
import StepCollectionDetails from './stepCollectionDetail'

const url = `mongodb://userId:user@pwd.mongodb.rds.aliyuncs.com:3717/admin`
const dbName = 'mars'

class _DBService {
    constructor() {
        this.client = new MongoClient(url, {
            // auth: { user, password },
            useUnifiedTopology: true
        })
    }

    async init() {
        await this.client.connect()
        console.log('mongodb connected')

        const db = this.client.db(dbName)

        this.elements = new Element(db)
        this.ajaxs = new Ajax(db)
        this.mocks = new Mock(db)
        this.suites = new Suite(db)
        this.suiteDetails = new SuiteDetail(db)
        this.configs = new Config(db)
        this.logs = new Log(db)
        this.screenshots = new Screenshot(db)
        this.baseEnvLogs = new BaseEnvLog(db)
        this.plans = new Plan(db)
        this.stepCollections = new StepCollection(db)
        this.stepCollectionDetails = new StepCollectionDetails(db)
    }


}

export default new _DBService()